/* 
 * File:   main.cpp
 * Author: PROG5
 *
 * Created on 8 avril 2013, 14:42
 */

#include <cstdlib>
#include <stdio.h>
#include <windows.h> 
#include <iostream>
#include <string>
#include "functionType.h"
#include "SSV_5_40/win32def.h"
#include "SSV_5_40/ssv.h"

using namespace std;


int main() {
    
    HINSTANCE LoadGIE;
    LoadGIE = LoadLibrary("C:\\Users\\PROG5.VISIODENT\\Desktop\\Working\\Techniques\\VisiodentTest\\SSV_5_40\\ssvw32.dll");
    cout << "Load lib: " << LoadGIE << endl;
        
    SSV_LireCartePS ssv_LireCartePS = 0;    
    SSV_InitLIB2 ssv_InitLib = 0;
    SSV_LireDroitsVitale ssv_LireDroitsVitale = 0;
    
    ssv_InitLib = (SSV_InitLIB2)GetProcAddress(LoadGIE, "SSV_InitLIB2");
    
    cout << "proc addr init Lib " << ssv_InitLib << endl;
    
    if (ssv_InitLib)
    {
        // Init Lib
        const char* szSesamPath = "C:\\Program Files\\santesocial\\fsv\\1.40.9\\conf\\sesam.ini";
        unsigned short usLib;
        usLib = ssv_InitLib(szSesamPath);
        cout << "invoke initLib " << usLib << endl;
        
        
        // Lire Carte PS
        ssv_LireCartePS = (SSV_LireCartePS)GetProcAddress(LoadGIE, "SSV_LireCartePS");
        cout << "Proc addr LirePS " << ssv_LireCartePS << endl;
        
        if (ssv_LireCartePS)
        {       
            void* pBufferOutPS =  NULL;
            unsigned int pSize = 0;
            unsigned short usLirePS = ssv_LireCartePS("CPS", "Vitale", "1234", &pBufferOutPS, &pSize);        
            
            //char* pBufferPS = (char*)pBufferOutPS;
            //string pBufferStrPS(pBufferPS); 
            
            cout << "invoke LirePS " << usLirePS << endl;
            //cout << "Data: " << pBufferStrPS.length() << endl;
           cout << "Data PS length: " << pSize << endl;
            
            // lire carte vitale
            ssv_LireDroitsVitale = (SSV_LireDroitsVitale)GetProcAddress(LoadGIE, "SSV_LireDroitsVitale");
            cout << "Proc addr LireDroitsVitale: " << ssv_LireDroitsVitale << endl;
            
            if (ssv_LireDroitsVitale)
            {
                void* pBufferOutVT = NULL;
                unsigned int pSizeVT = 0; 
                unsigned short usLireVitale = ssv_LireDroitsVitale("CPS", "Vitale", "1234", "20130408", &pBufferOutVT, &pSizeVT);        
                
                cout << "invoke LireDroitsVitale: " << usLireVitale << endl;
                cout << "Vitale size: " << pSizeVT << endl;
		char* pBufferVT = (char*)pBufferOutVT;
                cout << "Data Vitale: " << pBufferVT << endl;
                
            }
        }
    }
    
    FreeLibrary(LoadGIE);
    
    return 0;
}

